//const host = 'http://localhost:3000';
// const host = '';
export default {
    //host: 'http://localhost:3000',
	host: 'http://m8q4aj.natappfree.cc',
    // 注册接口
    register(obj) {
        return `${this.host}/api/register?username=${obj.username}&password=${obj.password}`;
    },
    // 登录接口
    login(obj) {
        return `${this.host}/api/login?username=${obj.username}&password=${obj.password}`;
    },
    // 修改密码接口
    changePassword(obj) {
        return `${this.host}/api/changepassword?username=${obj.username}&password=${obj.password}`;
    },
    // 修改用户信息接口
    changeInfomation(obj) {
        return `${this.host}/api/changeinfomation?username=${obj.username}&usernickname=${obj.usernickname}&useravatar=${obj.useravatar}&desc=${obj.desc}`;
    },
    // 获取用户信息接口
    getUserInfomation(obj) {
        return `${this.host}/api/getuserinfomation?username=${obj.username}`;
    },
    // 获取广告列表接口
    getAdvert() {
        return `${this.host}/api/getadvert`;
    },
    // 删除广告列表接口
    deleteAdvert(obj) {
        return `${this.host}/api/deleteadvert?id=${obj.id}`
    },
    // 修改广告信息接口
    changeAdvert(obj) {
        return `${this.host}/api/changeadvert?id=${obj['_id']}&title=${obj.title}&author=${obj.author}&src=${obj.src}&date=${obj.date}`
    },
    // 添加广告接口
    addAdvert(obj) {
        return `${this.host}/api/addadvert?title=${obj.title}&author=${obj.author}&src=${obj.src}&date=${obj.date}`
    },
    // 获取所有商品接口
    getGoods() {
        return `${this.host}/api/getallgoods`;
    },
    // 搜索商品接口
    selectGood(obj, pageNumber) {
        var arr = [];
        var str = `?pagenumber=${pageNumber}`;
        var arr1 = ['标准','小','中','大'];
        Object.keys(obj).forEach((key) => {
            if (key === 'id' && obj[key] !== '' || key === 'name' && obj[key] !== '') {
                arr.push([key, obj[key]])
            }
            if (key === 'size' && obj[key] !== '') {
                let str2 = obj[key];
                str2 = str2.substr(str2.length-1, 1);
                arr.push([key, arr1[str2]]);
            }
        })
        arr.forEach((val, index) => {
            let str1 = `${val[0]}=${val[1]}`;
            // if (index === 0) {
            //     str1 = '?' + str1;
            // } else {
                str1 = '&' + str1;
            // }
            str = str + str1;
        })
        return `${this.host}/api/selectgood${str}`;
    },
    // 添加商品接口
    addGood(obj) {
        return `${this.host}/api/addgood?name=${obj.name}&category=${obj.category}&introduce=${obj.introduce}&price=${obj.price}&size=${obj.size}`;
    },
    // 修改商品接口
    changeGoodInfomation(obj) {
        return `${this.host}/api/changegoodinfomation?pid=${obj['_id']}&id=${obj.id}&category=${obj.category}&introduce=${obj.introduce}&name=${obj.name}&price=${obj.price}&size=${obj.size}`;
    },
    // 删除商品接口
    deleteGood(obj) {
        return `${this.host}/api/deletegood?id=${obj['_id']}`;
    },
    // 查看商品评论接口
    getGoodComment(obj, pageNumber) {
        var arr = [];
        var str = `?pagenumber=${pageNumber}`;
        Object.keys(obj).forEach((key) => {
            if (key === 'id' && obj[key]!=='' || key === 'name' && obj[key]!=='') {
                arr.push([key, obj[key]]);
            }
        });
        arr.forEach((val, index) => {
            let str1 = `${val[0]}=${val[1]}`;
                str = str + '&' + str1;
        })
        // console.log(arr)
        return `${this.host}/api/getgoodcomment${str}`;
    },
    // 修改评论接口
    changeGoodComment(obj) {
        return `${this.host}/api/changegoodcomment?cid=${obj.cid}&commentuser=${obj.commentuser}&content=${obj.content}&pid=${obj.pid}`;
    },
    // 删除评论接口
    deleteGoodComment(obj) {
        return `${this.host}/api/deletegoodcomment?cid=${obj.cid}`;
    },
    // 查询所有订单接口
    getOrder() {
        return `${this.host}/api/getorder`;
    },
    // 查询订单接口
    selectOrder(obj, pageNumber) {
        var arr = [];
        var str = `?pagenumber=${pageNumber}`;
        Object.keys(obj).forEach((key) => {
            if (key === 'id' && obj[key]!=='' || key === 'username' && obj[key]!=='' || key === 'pid' && obj[key]!=='') {
                arr.push([key, obj[key]]);
            }
        });
        arr.forEach((val, index) => {
            let str1 = `${val[0]}=${val[1]}`;
                str = str + '&' + str1;
        })
        return `${this.host}/api/selectorder${str}`;
    },
    // 修改订单接口
    changeOrder(obj) {
        return `${this.host}/api/changeorder?oid=${obj.oid}&goodcount=${obj.goodcount}&orderend=${obj.orderend}&orderstart=${obj.orderstart}&pid=${obj.pid}&pname=${obj.pname}&username=${obj.username}&orderstartdate=${obj.orderstartdate}&orderenddate=${obj.orderenddate}&orderstate=${obj.orderstate}`;
    },
    // 添加订单接口
    addOrder(obj) {
        var year = new Date().getFullYear();
        var month = new Date().getMonth() + 1;
        month = parseInt(month) < 10 ? "0" + month : month;
        var date = new Date().getDate();
        date = parseInt(date) < 10 ? "0" + date : date;
        var orderstartdate = `${year}-${month}-${date}`;
        var addobject = {
            "orderstartdate": orderstartdate,
            "orderenddate": "",
            "orderstate": "未完成"
        };
        Object.assign(obj, addobject);
        return `${this.host}/api/addorder?goodcount=${obj.goodcount}&orderend=${obj.orderend}&orderstart=${obj.orderstart}&pname=${obj.pname}&username=${obj.username}&orderstartdate=${obj.orderstartdate}&orderenddate=${obj.orderenddate}&orderstate=${obj.orderstate}`;
    },
    // 删除订单接口
    deleteOrder(obj) {
        return `${this.host}/api/deleteorder?oid=${obj.oid}`;
    },
    // 查询所有用户接口
    getAllUsers() {
        return `${this.host}/api/getusers`;
    },
    // 查询特定用户接口
    selectUser(obj) {
        var arr = [];
        var str = '';
        Object.keys(obj).forEach((key) => {
            if (key === 'username' && obj[key] !== '') {
                arr.push([key, obj[key]])
            }
            if (key === 'usertype') {
                if (obj[key] !== '' && obj[key] !== '无要求') {
                    arr.push([key, obj[key]])
                }
            }
        })
        arr.forEach((val, index) => {
            var str1 = `${val[0]}=${val[1]}`;
            if (index === 0) {
                str = str + '?' + str1;
            } else {
                str = str + '&' + str1;
            }
        })
        // console.log(arr)
        return `${this.host}/api/selectuser${str}`;
    },
    // 修改用户信息接口
    changeUser(obj) {
        // console.log(obj)
        const { id, registerdate, usertype, vipenddate, vipstartdate} = obj;
        var str1 = `&vipstartdate=${vipstartdate}`;
        if (vipstartdate === '') {
            str1 = ''
        }
        var str2 = `&vipenddate=${vipenddate}`;
        if (vipenddate === '') {
            str2 = ''
        }
        return `${this.host}/api/changeuser?id=${id}&registerdate=${registerdate}&usertype=${usertype}${str1}${str2}`;
    }
}